home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Sleep Deprivation 1.1 / source / sd code ƒ / ◊ sd init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.3 KB  |  101 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        sd init.c
  4.  
  5. Purpose:    This module handles initialization at INIT time.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "sd init.h"
  25. #include "sd main.h"
  26. #include "sd environment.h"
  27. #include "notify.h"
  28. #include "Shutdown.h"
  29.  
  30. Handle            initHandle;            /* handle to main init code */
  31. THz                saveZone;
  32. SleepQRec        *theSleepPtr;
  33.     
  34. void __GetA4(void)
  35. {
  36.     asm {
  37.         bsr.s    @1
  38.         dc.l    0            ;  store A4 here
  39. @1        move.l    (sp)+,a1
  40.     }
  41. }
  42.  
  43. /* this be the init startup install routine thing */
  44. void main(void)
  45. {
  46.     RememberA0();
  47.     SetUpA4();
  48.     PrepareEnvironment();
  49.     if (!OkayEnvironmentQQ())
  50.     {
  51.         StartupError();
  52.     }
  53.     else
  54.     {
  55.         asm
  56.         {
  57.             movea.l            a4, a0
  58.             RecoverHandle
  59.             move.l            a0, initHandle
  60.         }
  61.         if (MemError())
  62.         {
  63.             StartupError();
  64.         }
  65.         else
  66.         {
  67.             HLock(initHandle);
  68.             HNoPurge(initHandle);
  69.             
  70.             DoSetup();
  71.             StartupGood();
  72.         }
  73.     }
  74.     
  75.     RestoreEnvironment();
  76.     RestoreA4();
  77. }
  78.  
  79. void DoSetup(void)
  80. {
  81.     theSleepPtr=(SleepQRec*)NewPtrSys(sizeof(SleepQRec));
  82.     theSleepPtr->sleepQLink=0;
  83.     theSleepPtr->sleepQType=slpQType;
  84.     theSleepPtr->sleepQProc=(ProcPtr)sdMain;
  85.     theSleepPtr->sleepQFlags=0;
  86.     SleepQInstall(theSleepPtr);
  87.     ShutDwnInstall((ProcPtr)&TheShutDownProc, sdOnDrivers+sdOnPowerOff);
  88. }
  89.  
  90. void TheShutDownProc(void)
  91. {
  92.     // for some reason, the system will call our sleep proc with a code "sleepDemand"
  93.     // on shutdown.  If we don't remove the sleep proc before this happens, this
  94.     // call will crash the machine with an error 41 (can't find "Finder" on disk).
  95.     // I offer no explanation, merely observation...
  96.     
  97.     SetUpA4();
  98.     SleepQRemove(theSleepPtr);
  99.     RestoreA4();
  100. }
  101.